//1.加载文件操作，fs模块
var fs = require("fs");
var path = require("path");
const autoSiderBar = function(dir, parent) {
  var mdDir = path.join(__dirname, "../", dir);
  let arr = fs.readdirSync(mdDir);

  var children = arr
    .filter(
      (x) =>
        !x.endsWith(".md") &&
        !x.endsWith(".txt") &&
        !x.startsWith("assets") &&
        fs.statSync(path.join(mdDir, x)).isDirectory()
    )
    .map((x) => {
      return {
        title: fs.readFileSync(path.join(mdDir, x, "title.txt")).toString(),
        collapsable: true,
        children: autoSiderBar(path.join(dir, x), path.join(parent || "", x)),
      };
    });

  const files = arr
    .filter((x) => x.endsWith(".md") && !x.startsWith("README"))
    .map((x) => (x.startsWith("README") ? "" : x.substr(0, x.length - 3)))
    .map((x) => path.join(dir, x))
    .map((x) => x.replace(/\\/g, "/"))
    .sort();

  children = [...children, ...files];

  // if (fs.existsSync(path.join(mdDir, "README.md"))) {
  //   children.splice(0, 0, '')
  // }
  console.log(children);

  return children;
};

module.exports = {
  title: "xkcyy的博客",
  lang: "zh-CN",
  description: "天地玄黄 宇宙洪荒 日月同驰 星河流淌",
  dest: "dist",
  head: [
    ["link", { rel: "icon", href: "/favicon.ico" }],
    [
      "meta",
      {
        name: "viewport",
        content: "width=device-width,initial-scale=1,user-scalable=no",
      },
    ],
  ],
  locales: {
    "/": {
      lang: "zh-CN", // 将会被设置为 <html> 的 lang 属性
    },
  },
  //base: '/blog/',
  base: require("./base-path").base,
  theme: "reco",
  //theme: require.resolve('../../packages/vuepress-theme-reco'),
  themeConfig: {
    noFoundPageByTencent: false,
    nav: [
      { text: "首页", link: "/", icon: "reco-home" },
      {
        text: "SpringCloud",
        icon: "reco-cloud",
        items: [
          {
            text: "OpenFeign",
            link: "/docs/springcloud/openfeign/01-use/01-base",
          },
          {
            text: "Sentinel",
            link: "/docs/springcloud/sentinel/01-use/01.集成控制台.md",
          },
        ],
      },
      {
        text: "java",
        icon: "reco-cloud",
        items: [
          {
            text: "Netty",
            link: "/docs/java/netty/01-IO模型",
          }
        ],
      },
      { text: "时间轴", link: "/timeline/", icon: "reco-date" },
      // { text: '码云', link: '/docs/sidebar/', icon: 'reco-mayun' }
    ],
    sidebar: {
      "/docs/springcloud/openfeign/": autoSiderBar("/docs/springcloud/openfeign/"),
      "/docs/springcloud/sentinel/": autoSiderBar("/docs/springcloud/sentinel/"),
      "/docs/java/netty/": autoSiderBar("/docs/java/netty/"),
    },
    type: "blog",
    // 博客设置
    blogConfig: {
      category: {
        location: 4, // 在导航栏菜单中所占的位置，默认2
        text: "分类", // 默认 “分类”
      },
      tag: {
        location: 5, // 在导航栏菜单中所占的位置，默认3
        text: "标签", // 默认 “标签”
      },
    },
    logo: "/xkcyy.png",
    authorAvatar: "/xkcyy.png",
    // 搜索设置
    search: true,
    searchMaxSuggestions: 10,
    // 自动形成侧边导航
    subSidebar: "auto",
    sidebarDepth: 4,
    // 最后更新时间
    lastUpdated: "最后更新时间",
    // 作者
    author: "xkcyy",
    // 备案号
    record: "xxxx",
    // 项目开始时间
    startYear: "2017",
    /**
     * 密钥 (if your blog is private)
     */
    friendLink: [
      // {
      //   title: '午后南杂',
      //   desc: 'Enjoy when you can, and endure when you must.',
      //   email: '1156743527@qq.com',
      //   link: 'https://www.recoluan.com'
      // },
      // {
      //   title: 'vuepress-theme-reco',
      //   desc: 'A simple and beautiful vuepress Blog & Doc theme.',
      //   avatar: "https://vuepress-theme-reco.recoluan.com/icon_vuepress_reco.png",
      //   link: 'https://vuepress-theme-reco.recoluan.com'
      // },
    ],
    /**
     * support for
     * '' | 'default'
     * 'coy'
     * 'dark'
     * 'funky'
     * 'okaidia'
     * 'solarizedlight'
     * 'tomorrow'
     * 'twilight'
     */
  },
  plugins: [
    // ['@vuepress-reco/vuepress-plugin-notice', {
    //   body: [
    //     {
    //       type: 'title',
    //       content: '欢迎加入QQ交流群 🎉🎉🎉',
    //       style: 'text-aligin: center;'
    //     },
    //     {
    //       type: 'image',
    //       src: '/rvcode_qq.png'
    //     }
    //   ],
    //   footer: [
    //     [
    //       {
    //         type: 'button',
    //         text: '打赏',
    //         link: '/donate'
    //       }
    //     ]
    //   ]
    // }]
  ],
};
